-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Compatibility Issue with Object Property Check Update use-draw.ts #708
base: main
Are you sure you want to change the base?
Conversation
This PR addresses a compatibility issue in the paths object by replacing the non-standard Object.hasOwn() method with the safer and more widely supported Object.prototype.hasOwnProperty.call(). This change ensures better cross-browser and cross-environment compatibility for property existence checks.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
if (!Object.hasOwn(paths, defaultLocale)) { | ||
if (!Object.prototype.hasOwnProperty.call(paths, defaultLocale)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm interesting, how many browsers wouldn't support hasOwn
This answer on stack overflow points that this is preferred https://stackoverflow.com/questions/69561596/object-hasown-vs-object-prototype-hasownproperty
Seems like most modern browsers support it?
This issue is stale because it has been open 45 days with no activity. Remove the |
Description:
Fixed an issue in the paths object where
Object.hasOwn(paths, defaultLocale)
was used to check for the presence of thedefaultLocale
key. WhileObject.hasOwn()
works in some environments, it is not a standard method in JavaScript and may cause compatibility issues across different platforms or environments.Issue
The code incorrectly used
Object.hasOwn(paths, defaultLocale)
, which is not part of the standard JavaScript API. The correct and safer method to check for the presence of a key in an object isObject.prototype.hasOwnProperty.call(paths, defaultLocale)
.Fix
Replaced
Object.hasOwn(paths, defaultLocale)
withObject.prototype.hasOwnProperty.call(paths, defaultLocale)
to ensure compatibility and to follow best practices for property checks in JavaScript.Importance
This change ensures better cross-environment compatibility, as
Object.hasOwn()
is not universally supported. Using the standardhasOwnProperty.call()
method is a safer and more reliable way to check for the presence of a property in an object. This fix improves code robustness and reduces the risk of runtime errors in different JavaScript environments.Checklist
pnpm spellcheck
?pnpm fmt
?pnpm lint
?